package main

import (
	"flag"
	"log"
	"net/http"
)

var addr = flag.String("port", ":6970", "http server addr")

func main() {
	//解析参数
	flag.Parse()
	hub := createHub()

	//运行后置服务
	go hub.run()

	//ws服务
	http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
		serveWs(hub, w, r)
	})

	//启动服务
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Panicln(err.Error())
	}
}
